/*************************************************************************
	> File Name: fly.h
	> Author: ma6174
	> Mail: ma6174@163.com 
	> Created Time: 2021年12月10日 星期五 20时41分12秒
 ************************************************************************/

#include<iostream>
#include <string>
#include <unordered_map>

struct Flyweight
{
	virtual void op(int state) = 0;
};

struct ConcreteFlyweight : public Flyweight
{
	virtual void op(int state)
	{
		std::cout << "具体Flyweight:\t" << state << std::endl;
	}
};

struct UnsharedConcreteFlyweight : public Flyweight
{
	virtual void op(int state)
	{
		std::cout << "不共享的具体Flyweight:\t" << state << std::endl;
	}
};

class FlyweightFactory
{
public:
	FlyweightFactory()
	{
		flyweights.insert(std::make_pair('X', new ConcreteFlyweight()));
		flyweights.insert(std::make_pair('Y', new ConcreteFlyweight()));
		flyweights.insert(std::make_pair('Z', new ConcreteFlyweight()));
	}

	Flyweight* getFlyweight(char key)
	{
		return flyweights[key];
	}

private:
	std::unordered_map<char, Flyweight*> flyweights;
};
